package com.example.Fragment;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.Base.BaseFragment;
import com.example.administrator.olddoctor.MainActivity;
import com.example.administrator.olddoctor.R;
import com.squareup.picasso.Picasso;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerSimple;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

import static android.content.Context.SENSOR_SERVICE;


/**
 * 关注
 */
public class AttentionFragment extends BaseFragment implements View.OnClickListener {
    private Context context;
    private View view;

    JCVideoPlayer.JCAutoFullscreenListener sensorEventListener;
    SensorManager sensorManager;
    JCVideoPlayerStandard jcVideoPlayerStandard0, jcVideoPlayerStandard1, jcVideoPlayerStandard2;
    Button tinyWindow;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = MainActivity.allThis;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        this.onCreate(savedInstanceState);
        view = inflater.inflate(R.layout.fragment_attention, container, false);

        tinyWindow = (Button) view.findViewById(R.id.tiny_window);
        tinyWindow.setOnClickListener(this);


        jcVideoPlayerStandard0 = (JCVideoPlayerStandard) view.findViewById(R.id.jc_video0);
        jcVideoPlayerStandard0.setUp("http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4"
                , JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "我是标题");
        Picasso.with(getActivity())
                .load("http://cos.myqcloud.com/1000264/qcloud_video_attachment/842646334/vod_cover/cover1458036374.jpg")
                .into(jcVideoPlayerStandard0.thumbImageView);

        jcVideoPlayerStandard1 = (JCVideoPlayerStandard) view.findViewById(R.id.jc_video1);
        jcVideoPlayerStandard1.setUp("http://video.jiecao.fm/8/17/bGQS3BQQWUYrlzP1K4Tg4Q__.mp4"
                , JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "我也是标题");
        Picasso.with(getActivity())
                .load("http://img4.jiecaojingxuan.com/2016/8/17/bd7ffc84-8407-4037-a078-7d922ce0fb0f.jpg")
                .into(jcVideoPlayerStandard1.thumbImageView);

        jcVideoPlayerStandard2 = (JCVideoPlayerStandard) view.findViewById(R.id.jc_video2);
        jcVideoPlayerStandard2.setUp("http://video.jiecao.fm/8/16/%E4%BF%AF%E5%8D%A7%E6%92%91.mp4"
                , JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "我也是标题");
        Picasso.with(getActivity())
                .load("http://img4.jiecaojingxuan.com/2016/8/16/e565f9cc-eedc-45f0-99f8-5b0fa3aed567.jpg")
                .into(jcVideoPlayerStandard2.thumbImageView);

        sensorEventListener = new JCVideoPlayer.JCAutoFullscreenListener();
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tiny_window:
                showToast("点击了悬浮窗");
                jcVideoPlayerStandard0.startWindowTiny();
                break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
//        Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
//        sensorManager.registerListener(sensorEventListener, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

    @Override
    public void onPause() {
        super.onPause();
//        sensorManager.unregisterListener(sensorEventListener);
        JCVideoPlayer.releaseAllVideos();
    }

}
